//package com.xnyy.lottery.security;
//
//import cn.hutool.json.JSONUtil;
//import com.xnyy.lottery.common.CommonResult;
//import com.xnyy.lottery.util.JwtUtils;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
//import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
//import org.springframework.stereotype.Component;
//
//import javax.servlet.ServletException;
//import javax.servlet.ServletOutputStream;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.nio.charset.StandardCharsets;
//
//@Component
//public class JWTLogoutSuccessHandler implements LogoutSuccessHandler {
//
//    private final JwtUtils jwtUtils;
//
//    public JWTLogoutSuccessHandler(JwtUtils jwtUtils) {
//        this.jwtUtils = jwtUtils;
//    }
//
//    @Override
//    public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
//
//        if (authentication != null) {
//            new SecurityContextLogoutHandler().logout(httpServletRequest, httpServletResponse, authentication);
//        }
//
//        httpServletResponse.setContentType("application/json;charset=UTF-8");
//        ServletOutputStream outputStream = httpServletResponse.getOutputStream();
//
//        httpServletResponse.setHeader(jwtUtils.getHeader(), "");
//
//        CommonResult result = CommonResult.success("登出成功");
//
//        outputStream.write(JSONUtil.toJsonStr(result).getBytes(StandardCharsets.UTF_8));
//        outputStream.flush();
//        outputStream.close();
//    }
//}
